<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: url('./img/loginbg.jpeg') no-repeat;
            background-size: 100% 130%;
        }

        #login_box {
            width: 20%;
            height: 400px;
            background-color: #00000060;
            margin: auto;
            margin-top: 10%;
            text-align: center;
            border-radius: 10px;
            padding: 50px 50px;
        }

        h2 {
            color: #ffffff90;
            margin-top: 5%;
        }

        #input-box {
            margin-top: 5%;
        }

        span {
            color: #fff;
        }

        input {
            border: 0;
            width: 60%;
            font-size: 15px;
            color: #fff;
            background: transparent;
            border-bottom: 2px solid #fff;
            padding: 5px 10px;
            outline: none;
            margin-top: 10px;
        }

        button {
            margin-top: 50px;
            width: 60%;
            height: 30px;
            border-radius: 10px;
            border: 0;
            color: #fff;
            text-align: center;
            line-height: 30px;
            font-size: 15px;
            background-image: linear-gradient(to right, #30cfd0, #330867);
        }

        #sign_up {
            margin-top: 45%;
            margin-left: 60%;
        }

        a {
            color: #b94648;
        }
    </style>
</head>

<body>
<div id="login_box">
    <h2>LOGIN</h2>

    <form id="login-form">
        <div id="input_box">
            <input name="username" type="text" placeholder="请输入用户名">
        </div>
        <div class="input_box">
            <input name="password" type="password" placeholder="请输入密码">
        </div>

    </form>

    <button onclick="login()">登录</button>


</div>

<script src="./js/jquery-3.3.1.js"></script>
<script src="./js/common.js"></script>
<script>

    function login() {

        let data = $('#login-form').serialize()
        console.log(data)

        $.ajax({
            url: baseUrl + '/admin/login',
            method: 'post',
            data: data,
            success(result) {
                console.log(result)
                if (result.code == 200) {   // 登录成功
                    // 存储数据
                    sessionStorage.setItem("username", result.data.username)
                    // 页面跳转
                    location.href = baseUrl
                } else { // 登录失败
                    alert(result.msg)
                }

            },
            error(e) {
                alert(e)
            }
        })

    }

</script>



</body>
</html>

